// pages/myinfo/orderList/orderList.js
var app = getApp();
const publics = require('../../../utils/public.js');
const md5 = require('../../../utils/md5.js');
const http = require('../../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
        addMsg:[
          // { add: '西湖区', state: '已完成 >', stateNum: 1, time: '2018年4月03号', hour: '20:59:02', address: '华星时代广场网点A21号', area: '城西银泰城', coundDown: '2小时20分50秒', price: '花费30元', url:'/pages/myinfo/orderList/ordercomplete/ordercomplete'},
          //   { add: '西湖区', state: '待评价 >', stateNum: 2, time: '2018年4月03号', hour: '20:59:02', address: '华星时代广场网点A21号', area: '城西银泰城', coundDown: '2小时20分50秒', price: '花费30元', url: '/pages/myinfo/orderList/ordeToEvaluated/ordeToEvaluated' },
          //   { add: '西湖区', state: '未完成 >', stateNum: 3, time: '2018年4月03号', hour: '20:59:02', address: '华星时代广场网点A21号', area: '', coundDown: '2小时20分50秒', price: '未付款', url: '/pages/myinfo/orderList/orderTheTough/orderTheTough' },
          //   { add: '西湖区', state: '已关闭 >', stateNum: 4, time: '2018年4月03号', hour: '20:59:02', address: '华星时代广场网点A21号', area: '城西银泰城', coundDown: '2小时20分50秒', price: '未付款', url: '/pages/myinfo/orderList/orderClose/orderClose' }
        ],
        url:'',
        orderId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var token = wx.getStorageSync('token')
    var data = {
      method: 'Order.listing',
      token: token,
    }
    var arr = http.sorts(data)
    var that = this
    data.sign = md5.hex_md5(arr)
    http._post(data, res => { 
      //console.log(res.data.data.orderList)
      var orderList = res.data.data.orderList
      var addMsg = that.data.addMsg
      var url = that.data.url
      for (var i = 0; i < orderList.length;i++){
        addMsg[i] = orderList[i]
        //console.log(addMsg[i].orderId)
        var orderId = addMsg[i].orderId
        that.setData({
          addMsg: addMsg,
          orderId: orderId
        })    
      }

     
    })
  },
  bind_url:function(e){
    console.log(e)
    var index = e.currentTarget.dataset.id
    var statusInfo = this.data.addMsg[index].statusInfo
    var orderId = this.data.addMsg[index].orderId
    var startingUpTime = this.data.addMsg[index].startingUpTime
    // console.log(mas)
    if (statusInfo ==='未完成 >'){
        wx.navigateTo({
          url: '/pages/myinfo/orderList/orderTheTough/orderTheTough?orderId=' + orderId + "&startingUpTime=" + startingUpTime,
        })
    } else if (statusInfo === '已完成 >'){
        wx.navigateTo({
          url: '/pages/myinfo/orderList/ordercomplete/ordercomplete?orderId=' + orderId + "&startingUpTime=" + startingUpTime,
        })
    } else if (statusInfo === '待评价 >'){
        wx.navigateTo({
          url: '/pages/myinfo/orderList/ordeToEvaluated/ordeToEvaluated?orderId=' + orderId + "&startingUpTime=" + startingUpTime,
        })
    } else {
      wx.navigateTo({
        url: '/pages/myinfo/orderList/orderClose/orderClose?orderId=' + orderId + "&startingUpTime=" + startingUpTime,
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})